home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0084_Re: Splitter Component.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  4.7 KB  |  153 lines

  1.  
  2. *****************************************************************************
  3. The following component might help you.
  4. This is derived from TCustomPanel
  5. To install:
  6.         Put this source in a unit.
  7.         Compile to a DCU
  8.         Install it on a component palette
  9. To use:
  10.         To use as vertical split.
  11.                 1. Put a panel in the form. Align it to the top 
  12.                     Let us call it DynamicPanel
  13.                     Set Align property to alTop
  14.                 2. Add the TSplitBar component,
  15.                     Set the SplitStyle property to splitVertical
  16.                     Set Align property to alTop
  17.                      Set the AdjucentControl to DynamicPanel
  18.                3. Add a third panel and set Align property to alClient
  19.                  4. Run the application. Click and drag the splitbar 
  20.                 5. Is this what you wanted.
  21.  
  22. You can make horizontal or vertical split, combination of both, any no
  23. of splits in a single form. Just use the TPanel, TSplitBar and Align
  24. properties with imaginations.
  25.  
  26. **** BUG ****
  27. If you assign a control as the AdjuscentControl and later delete it,
  28. this won't be reflected in the SplitBar component. This might generate
  29. faults.
  30. There are few more improvements that can be made. Correct it and
  31. enjoy.
  32. ***************
  33.  
  34. kind regards
  35. R.Venkatesh
  36.  
  37. { ************* The source starts here ****************** }
  38. unit Splitbar;
  39.  
  40. interface
  41.  
  42. uses
  43.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  44.   Forms, Dialogs, ExtCtrls;
  45.  
  46. type
  47.   TSplitStyles = ( splitVertical, splitHorizontal );
  48.  
  49.   TSplitBar = class(TCustomPanel)
  50.   private
  51.      FSplitStyle : TSplitStyles;
  52.      InResize    : Boolean;
  53.      FAdjControl : TWinControl;
  54.      OldX, OldY  : Integer;
  55.  
  56.      procedure SetSplitStyle(TheStyle : TSplitStyles);
  57.  
  58.   protected
  59.      procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
  60.                                  X, Y: Integer); Override;
  61.  
  62.      procedure MouseMove( Shift: TShiftState; X,Y : Integer);
  63. Override;
  64.      procedure MouseUp( Button: TMouseButton; Shift: TShiftState;
  65.                                  X, Y: Integer); Override;
  66.   public
  67.      constructor Create( AOwner : TComponent); override;
  68.      destructor Destroy; override;
  69.   published
  70.      property Align;
  71.      property AdjucentControl : TWinControl read FAdjControl write
  72. FAdjControl;
  73.      property Enabled;
  74.      property ShowHint;
  75.      property SplitStyle : TSplitStyles read FSplitStyle write
  76. SetSplitStyle;
  77.   end;
  78.  
  79. procedure Register;
  80.  
  81. implementation
  82.  
  83. {*****************************************************************************}
  84. procedure Register;
  85. begin
  86.   RegisterComponents('Samples', [TSplitBar]);
  87. end;
  88. {.........................................................................}
  89. constructor TSplitBar.Create( AOwner : TComponent );
  90. begin
  91.    inherited Create(AOwner);
  92.    Caption     := ' ';
  93.    InResize    := False;
  94. end;
  95. {.........................................................................}
  96. destructor TSplitBar.Destroy;
  97. begin
  98.    inherited Destroy;
  99. end;
  100. {.........................................................................}
  101. procedure TSplitBar.SetSplitStyle(TheStyle : TSplitStyles);
  102. begin
  103.    FSplitStyle := TheStyle;
  104.    { The following code is unncessory. 
  105.       You can do this in design time itself }
  106.    if TheStyle = splitVertical then
  107.    begin
  108.       Align := alTop;
  109.       Cursor := crVSplit;
  110.    end
  111.    else
  112.    begin
  113.       Align := alLeft;
  114.       Cursor := crHSplit;
  115.    end;
  116. end;
  117. {.........................................................................}
  118. procedure TSplitBar.MouseDown( Button: TMouseButton; Shift:
  119.                                 TShiftState;   X, Y: Integer);
  120. begin
  121.    inherited MouseDown(Button, Shift, X, Y);
  122.    If NOT Enabled Then Exit;
  123.    if FAdjControl = Nil then Exit;
  124.    InResize := True;
  125.    OldX := X;
  126.    OldY := Y;
  127. end;
  128. {.........................................................................}
  129. procedure TSplitBar.MouseMove( Shift: TShiftState; X,Y: Integer);
  130. begin
  131.    inherited MouseMove( Shift, X, Y);
  132.    if InResize then
  133.    begin
  134.       if FSplitStyle = splitHorizontal then
  135.          FAdjControl.Width := FAdjControl.Width + (X - OldX)
  136.       else
  137.          FAdjControl.Height := FAdjControl.Height + (Y - OldY)
  138.    end;
  139. end;
  140. {.........................................................................}
  141. procedure TSplitBar.MouseUp( Button: TMouseButton; Shift: TShiftState;
  142.                              X, Y: Integer);
  143. begin
  144.    inherited MouseUp( Button, Shift, X, Y);
  145.    InResize := False;
  146. end;
  147.  
  148. {.........................................................................}
  149.  
  150. end.
  151.  
  152. { ********** End of source ********************** }
  153.